﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Bymed.SpineScan.DataModel.TestItem
{
    public class RotationTest : TestItemBase
    {
        public RotationTest(string testMessage)
            : base(testMessage)
        {
            TestItemName = TestItemDefinition.RotationTestName;
        }

        /// <summary>
        /// Get the test result by using specified pattern from the test message comes from device.
        /// It is invoked by base constructor.
        /// </summary>
        protected override void GetTestResult()
        {
            TestMessagePattern = "Rotation s=[0-9]+ l=(?<Left>-*[0-9]+) r=(?<Right>-*[0-9]+)";
            var regex = new Regex(TestMessagePattern, RegexOptions.IgnoreCase);
            var matches = regex.Matches(ResultRawData);

            if (matches.Count > 0)
            {
                FirstResult = Math.Abs(int.Parse(matches[0].Groups["Left"].Value));
                SecondResult = Math.Abs(int.Parse(matches[0].Groups["Right"].Value));
            }
        }
    }
}
